package main

import (
	"fmt"
)

type MinStack struct {
	stack     []int
	helpStack []int
}


func Constructor() MinStack {
	return MinStack{
		stack:     []int{},
		helpStack: []int{},
	}
}


func (this *MinStack) Push(val int)  {
	this.stack = append(this.stack,val)
	//如果辅助栈为空或者val小于辅助栈栈顶元素 则辅助栈入栈
	//if this.helpStack == nil || val < this.helpStack[len(this.helpStack)-1]{
	//	this.helpStack = append(this.helpStack,val)
	//}
	if this.helpStack == nil{
		this.helpStack = append(this.helpStack,val)
	}else if val <= this.helpStack[len(this.helpStack)-1]{
		this.helpStack = append(this.helpStack,val)
	}
}


func (this *MinStack) Pop()  {
	//如果元素栈栈顶的元素等于辅助栈栈顶元素 则两个栈都出栈 否则元素栈出栈
	if this.helpStack[len(this.helpStack)-1] == this.stack[len(this.stack)-1]{
		this.stack = this.stack[:len(this.stack)-1]
		this.helpStack = this.helpStack[:len(this.helpStack)-1]
	}else{
		this.stack = this.stack[:len(this.stack)-1]
	}

}

func (this *MinStack) Top() int {
	return this.stack[len(this.stack)-1]
}

func (this *MinStack) Min() int {
	return this.helpStack[len(this.helpStack)-1]
}

func main() {
	ss:=&MinStack{}
	ss.Push(-2)
	ss.Push(0)
	ss.Push(-3)
	fmt.Println(ss)
	fmt.Println(ss.Min())
	ss.Pop()
	fmt.Println(ss.Top())
	fmt.Println(ss.Min())
}
